<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="disabled">
      <a-form-model layout="horizontal" ref="subForm" slot="detail" :model="model" :rules="validatorRules" v-bind="formItemLayout">
        <z-form-item :datas="fieldArr" :form="model" :rules="validatorRules" :gutter="0">
          <!--//自定义吸毒查获情况-->
          <template slot="slots-drugSeizures">
            <a-textarea v-for="(item, index) in drugSeizures" :key="index" :value="item" disabled placeholder="请输入" :auto-size="{ minRows: 3, maxRows: 5 }" />
          </template>
        </z-form-item>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
  import { riskLevelEvalApply, reRiskLevelEvalApply } from '@/api/sjsk/clinicmanageService'
  export default {
    props: {
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model: {},
        confirmLoading: false,
        formItemLayout: {
          labelCol: { span: 6 },
          wrapperCol: { span: 16 }
        },
        status: null,
        drugSeizures: [],
        fieldArr: [
          {label: '评估对象姓名', prop: 'realName', tagType: 'input', disabled: true},
          {label: '性别', prop: 'sex', tagType: 'dict-select', dictCode:'sex', disabled: true},
          {label: '籍贯', prop: 'country', tagType: 'dict-select', dictCode:'country', disabled: true},
          {label: '民族', prop: 'nation', tagType: 'dict-select', dictCode:'nation', disabled: true},
          {label: '出生日期', prop: 'birthday', tagType: 'date-picker', format: 'YYYY-MM-DD', disabled: true},
          {label: '文化程度', prop: 'education', tagType: 'dict-select', dictCode:'degreeEducation', disabled: true},
          {label: '身份证号', prop: 'identityCard', tagType: 'input', disabled: true},
          {label: '联系方式', prop: 'phone', tagType: 'input', disabled: true},
          {label: '户籍地详址', prop: 'householdAddress', tagType: 'input', disabled: true},
          {label: '现居住地', prop: 'currentAddress', tagType: 'input', disabled: true},
          {label: '管辖地区', prop: 'currentTown', tagType: 'input', disabled: true},
          {label: '管辖派出所', prop: 'currentPoliceStation', tagType: 'input', disabled: true},
          {label: '人员类型', prop: 'personType', tagType: 'dict-select', dictCode:'risk_level_person_type', disabled: true},
          {label: '当前管控现状', prop: 'currentControlStatus', tagType: 'dict-select', dictCode:'control_level', disabled: true},
          {label: '当前管控现状时间', prop: 'currentControlTime', tagType: 'date-picker', format: 'YYYY-MM-DD', disabled: true},
          {label: '当前风险等级', prop: 'currentRiskLevel', tagType: 'dict-select', dictCode:'risk_level', disabled: true},
          {label: '吸毒查获情况', prop: 'drugSeizures'},
          {label: '申请评估等级', prop: 'applyLevel', tagType: 'dict-select', dictCode:'risk_category'},
          {
            label: '走访人员',
            prop: 'interviewPerson',
            tagType: 'dict-multi-tag',
            dictOptions: [
              { text: '父母', value: '1' },
              { text: '兄妹', value: '2' },
              { text: '配偶', value: '3' },
              { text: '居住地邻居', value: '4' },
              { text: '社区（村居）干部', value: '5' },
            ],
            type:'checkbox'
          },
          {label: '评估依据', prop: 'evaluationBasis', tagType: 'textarea',},
          {label: '材料说明', prop: 'file', tagType: 'upload-file', fileDescribe: '可上传多个附件'},
        ],
        validatorRules: {
          applyLevel:[ { required: true, message: '请选择申请评估等级!' }],
          interviewPerson:[ { required: true, message: '请选择走访人员!' }],
          evaluationBasis:[ { required: true, message: '请输入!' }],
          file:[ { required: true, message: '请上传材料说明!' },]
        }
      }
    },
    methods: {
      show (record) {
        // this.model = record?Object.assign({}, record):this.model;
        this.status =  record.status
        this.$set( this.model, 'id', record.id )
        this.$set( this.model, 'personId', record.personId )
        this.$set( this.model, 'sources', record.sources )
        this.$set( this.model, 'realName', record.realName )
        this.$set( this.model, 'sex', record.sex )
        this.$set( this.model, 'country', record.country )
        this.$set( this.model, 'nation', record.nation )
        this.$set( this.model, 'birthday', record.birthday )
        this.$set( this.model, 'education', record.education )
        this.$set( this.model, 'identityCard', record.identityCard )
        this.$set( this.model, 'phone', record.phone )
        this.$set( this.model, 'householdAddress', record.householdAddress )
        this.$set( this.model, 'currentAddress', record.currentAddress )
        this.$set( this.model, 'currentTown', record.currentTown )
        this.$set( this.model, 'currentPoliceStation', record.currentPoliceStation )
        this.$set( this.model, 'personType', record.personType )
        this.$set( this.model, 'currentControlStatus', record.currentControlStatus )
        this.$set( this.model, 'currentControlTime', record.currentControlTime )
        this.$set( this.model, 'currentRiskLevel', record.risk_category )
        this.drugSeizures = ['122', '2344']
        this.$set( this.model, 'drugSeizure', this.drugSeizures.toString() )
      },
      submitForm () {
        const parameter = Object.assign({}, this.model)
        this.$refs.subForm.validate((valid)=> {
          if (valid) {
            let api = null
            if(this.status==4) { //重新申请风险等级评估
              api = reRiskLevelEvalApply(parameter)
            } else { //风险等级评估申请
              api = riskLevelEvalApply(parameter)
            }
            if(!api) return
            api.then(res => {
              this.confirmLoading = false
              if (res.success) {
                this.$message.success(res.message)
                this.$emit('ok');
              } else {
                this.$message.warn(res.message)
              }
            })
            .catch(e => {
              this.$message.warn('请求失败！')
              this.confirmLoading = false
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    }
  }
</script>
